package com.zygh.interactiveplatform.module.service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zygh.interactiveplatform.common.constant.EmployeeResponseCodeConst;
import com.zygh.interactiveplatform.common.domain.ResponseDTO;
import com.zygh.interactiveplatform.module.entity.DataStructure;
import com.zygh.interactiveplatform.module.entity.StorageTrends;
import com.zygh.interactiveplatform.module.mapper.StorageTrendsMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author lee
 * @since 2021-02-01
 */
@Service
public class StorageTrendsService extends ServiceImpl<StorageTrendsMapper, StorageTrends> {
    @Resource
    private StorageTrendsMapper storageTrendsMapper;

    public ResponseDTO addStorageTrends(StorageTrends storageTrends) {
        int insert = storageTrendsMapper.insert(storageTrends);
        if (insert > 0) {
            return ResponseDTO.succ();
        }
        return ResponseDTO.wrap(EmployeeResponseCodeConst.ADD_EXIST);
    }

    public ResponseDTO updateStorageTrends(StorageTrends storageTrends) {
        int insert = storageTrendsMapper.updateById(storageTrends);
        if (insert > 0) {
            return ResponseDTO.succ();
        }
        return ResponseDTO.wrap(EmployeeResponseCodeConst.UPDATE_EXIST);
    }
    public ResponseDTO deleteStorageTrends(Integer id) {
        int insert = storageTrendsMapper.deleteById(id);
        if (insert > 0) {
            return ResponseDTO.succ();
        }
        return ResponseDTO.wrap(EmployeeResponseCodeConst.DELETE_EXIST);
    }
    public ResponseDTO findStorageTrendsAll(Integer current, Integer size) {
        PageHelper.startPage(current, size);
        List<StorageTrends> storageTrendss = storageTrendsMapper.selectList(null);
        if (storageTrendss != null) {
            PageInfo<StorageTrends> pageInfo = new PageInfo<>(storageTrendss);
            return ResponseDTO.succData(pageInfo);
        }
        return ResponseDTO.wrap(EmployeeResponseCodeConst.EMPTY_INFORMATION_ERROR);
    }

    public ResponseDTO findStorageTrendsAllDay() {
        List<StorageTrends> storageTrendss = storageTrendsMapper.findStorageTrendsAllDay();
        if (storageTrendss != null) {
            return ResponseDTO.succData(storageTrendss);
        }
        return ResponseDTO.wrap(EmployeeResponseCodeConst.EMPTY_INFORMATION_ERROR);
    }

    public ResponseDTO findStorageTrendsLast() {
        StorageTrends storageTrends = storageTrendsMapper.findStorageTrendsLast();
        if (storageTrends != null) {
            return ResponseDTO.succData(storageTrends);
        }
        return ResponseDTO.wrap(EmployeeResponseCodeConst.EMPTY_INFORMATION_ERROR);
    }
}
